import request from '@/utils/request'
import defaultSettings from '@/settings'

export const apiUrlConfig = {
  queryUrl: `${defaultSettings.ctx.authorityApp}/s/roleInfo/search`,
  exportUrl: `${defaultSettings.ctx.authorityApp}/s/roleInfo/search`,
  delUrl: `${defaultSettings.ctx.authorityApp}/s/roleInfo/remove`,
}

// 查询角色列表
export function listRoleInfo(query) {
  return request({
    url: `${defaultSettings.ctx.authorityApp}/s/roleInfo/search`,
    method: 'get',
    params: query
  })
}

// 查询角色详细
export function findRoleInfo(roleInfoId) {
  return request({
    url: `${defaultSettings.ctx.authorityApp}/s/roleInfo/` + praseStrEmpty(roleInfoId),
    method: 'get'
  })
}

// 新增角色
export function addRoleInfo(data) {
  return request({
    headers: {
      'Content-Type' : 'application/json'
    },
    url: `${defaultSettings.ctx.authorityApp}/s/roleInfo/add`,
    method: 'post',
    data: data
  })
}

// 修改角色
export function updateRoleInfo(data) {
  return request({
    headers: {
      'Content-Type' : 'application/json'
    },
    url: `${defaultSettings.ctx.authorityApp}/s/roleInfo/edit`,
    method: 'post',
    data: data
  })
}

// 删除角色
export function delRoleInfo(ids) {
  return request({
    url: `${defaultSettings.ctx.authorityApp}/s/roleInfo/remove?ids=${ids}`,
    method: 'get'
  })
}

// 删除角色
export function changeStatus(data) {
  return request({
    url: `${defaultSettings.ctx.authorityApp}/s/roleInfo/changeStatus`,
    method: 'post',
    data:data
  })
}


// 查询菜单列表
export function allMenuTreeNew(tenantCode) {
  return request({
    url: `${defaultSettings.ctx.authorityApp}/s/menuInfo/allMenuTreeNew?tenantCode=${tenantCode}`,
    method: 'get'
  })
}


// 查询角色菜单列表
export function listRoleMenuList(query) {
  return request({
    url: `${defaultSettings.ctx.authorityApp}/s/menuInfo/roleMenuTreeNew`,
    method: 'get',
    params: query
  })
}

// 查询角色菜单列表
export function checkRoleName(id,roleName) {
  return request({
    url: `${defaultSettings.ctx.authorityApp}/s/roleInfo/checkRoleNameUnique?roleName=${roleName}&id=${id}`,
    method: 'get'
    
  })
}

// 查询角色菜单列表
export function checkRoleKey(id,roleKey) {
  return request({
    url: `${defaultSettings.ctx.authorityApp}/s/roleInfo/checkRoleKeyUnique?roleKey=${roleKey}&id=${id}`,
    method: 'get'
  })
}

// 查询当前登陆人可看的租户列表
export function getMyTenants() {
  return request({
    url: `${defaultSettings.ctx.authorityApp}/s/tenantInfo/getMyTenants`,
    method: 'get'
  })
}


// 校验当前登陆人是否有权限修改角色
export function checkRoleUpdatePermission(tenantCode) {
  return request({
    url: `${defaultSettings.ctx.authorityApp}/s/roleInfo/checkRoleUpdatePermission?tenantCode=${tenantCode}`,
    method: 'get'
  })
}

// 查询用户列表
export function rolesByUserId(userId,deptId,tenantCode) {
  return request({
    url: `${defaultSettings.ctx.authorityApp}/s/roleInfo/getRolesByUserIdVue?userId=`+userId+`&deptId=`+deptId+`&tenantCode=`+tenantCode,
    method: 'get'
  })
};
export function userRolesByUserId(userId,deptId) {
  return request({
    url: `${defaultSettings.ctx.authorityApp}/s/roleInfo/getUserRolesByUserIdVue?userId=`+userId+`&deptId=`+deptId,
    method: 'get'
  })
};
